from pathlib import Path
from typing import List
import os
import secrets

# Application configuration
class Settings:
    def __init__(self):
        # Application name and description
        self.APP_NAME = "DICOM Server"
        self.APP_DESCRIPTION = "DICOM file server based on FastAPI"
        
        # Server configuration
        self.HOST = "0.0.0.0"
        self.PORT = 8000
        
        # CORS configuration
        self.ALLOWED_ORIGINS = ["*"]  # Should be set to specific frontend addresses in production
        
        # File storage configuration
        self.BASE_DIR = Path(__file__).parent.parent.parent
        self.DICOM_STORAGE = self.BASE_DIR / "dicom_files"
        self.DICOM_IMG_STORAGE = self.BASE_DIR / "dicom_img"
        
        # Database configuration
        self.DB_HOST = os.getenv("DB_HOST", "localhost")
        self.DB_PORT = int(os.getenv("DB_PORT", 3306))
        self.DB_NAME = os.getenv("DB_NAME", "probenicedb")
        self.DB_USER = os.getenv("DB_USER", "root")
        self.DB_PASSWORD = os.getenv("DB_PASSWORD", "Jwht123456@")
        
        # Security configuration
        self.SECRET_KEY = os.getenv("SECRET_KEY", secrets.token_urlsafe(32))
        self.ALGORITHM = "HS256"
        self.ACCESS_TOKEN_EXPIRE_MINUTES = 30
        
        # Ensure storage directories exist
        self.ensure_directories()
    
    def ensure_directories(self):
        self.DICOM_STORAGE.mkdir(exist_ok=True)
        self.DICOM_IMG_STORAGE.mkdir(exist_ok=True)

# Create global configuration instance
settings = Settings()